<?php
class tax
	{
	private $taxname;
	private $taxrate;
     private function set($nm,$rt)
	 {
		 $this->taxname=addslashes(strip_tags(trim($nm)));
		 $this->taxrate=trim($rt);
	 }
	 private function check()
	 {
		 if( !empty($this->taxname) && !empty($this->taxrate))return true;
		 else return false;
	 }
	 function getAllTax()
	 {
return  mysql_query('SELECT sme_tax. * , count( productId )  FROM sme_tax LEFT JOIN sme_product ON proTax = taxid AND sme_product.delete <> 1 GROUP BY taxid ORDER BY taxid ASC');	 
	 }
	 function getTax($id)
	 {
		return  mysql_fetch_array(mysql_query("SELECT * FROM  sme_tax WHERE taxid = $id"));	  
	 }
	 function haveRow($id)
	 { 
		if(mysql_num_rows(mysql_query("SELECT * FROM  sme_tax WHERE taxid = '$id'"))==1)return TRUE;
		else return FALSE;
	 }
	 function insert($nm,$rt)
	 {
		 $this->set($nm,$rt);
		 if($this->check())
		 return mysql_query("INSERT INTO sme_tax VALUES ('1', '$this->taxname', '$this->taxrate')");
		 else return false;
	 }
	 function update($nm,$rt,$id)
	 {
		 $this->set($nm,$rt);
		 if($this->check() && $this->haveRow($id))
		 return mysql_query("UPDATE sme_tax SET taxname = '$this->taxname', taxrate = '$this->taxrate' WHERE taxid = $id ");
		 else return false;
	 }
	 function delete($id)
	 {
		 if($this->haveRow($id))
		 {
		$d= mysql_query("DELETE FROM sme_tax WHERE sme_tax.taxid = $id");
		 mysql_query("OPTIMIZE TABLE `sme_tax`");
		 return $d;
		 }return FALSE;
		 
	 }
	  function havetax()
	 { 
		if(mysql_num_rows(mysql_query("SELECT * FROM  sme_tax"))>0)return TRUE;
		else return FALSE;
	 }
	}

function taxEC($action,$txt)
{	return base64_encode("$action=".base64_encode($txt." TAX") ) ;}
function taxDC($action,$txt)
{
 $decode =explode("=",base64_decode($txt));
 
 if($decode[0]==$action)
 {   $DC=explode(" ",base64_decode($decode[1]));
 		if($DC[1]=="TAX")return $DC[0];
		else return FALSE;
 }
 else return FALSE;
}
	
?>